#ifndef __SW_CONTACT_LISTENER_H__
#define __SW_CONTACT_LISTENER_H__

#include <Box2D\Box2D.h>
#include "globals.h"

const int32 k_maxContactPoints = 2048;
struct ContactPoint
{
	b2Fixture* fixtureA;
	b2Fixture* fixtureB;
	b2Vec2 normal;
	b2Vec2 position;
	b2PointState state;
};

class sw_contact_listener : public b2ContactListener
{
    int32 m_pointCount;
    ContactPoint m_points[k_maxContactPoints];

    public:
	sw_contact_listener() {
		
	}
    void BeginContact(b2Contact* contact)
        {
            //b2Fixture* fixtureA = contact->GetFixtureA();
            //b2Fixture* fixtureB = contact->GetFixtureB();
			global_sound_manager->play_sound(sw_sound_manager::SW_SOUND_ENEMY_DEATH, true);
            //if (contact->IsSolid()) {
            //   NSLog(@"Contact is solid");
            // }
        }

    void EndContact(b2Contact* contact)
        {
            //NSLog(@"end contact");
        }

    void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
        {
           const b2Manifold* manifold = contact->GetManifold();
        }

    void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
        {
            //const b2ContactImpulse* impulse;
			float x = 0;
			float y = 0;
			for (int i=0; i<impulse->count; i++) {
				x += impulse->normalImpulses[i];
				y += impulse->tangentImpulses[i];
			}
			float tot = sqrt(x*x + y*y);
			global_life -= global_life_factor*tot;
        }
};

#endif